/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package familytree.struts.forms;

import familytree.persistencia.pojos.Evento;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.util.LabelValueBean;

/**
 *
 * @author Jose
 */
public class EventoForm extends org.apache.struts.action.ActionForm {
    
   private Evento evento;
   private String dia,mes,anyo;
   

   /**
    * @return
    */
   public Evento getEvento() {
       return evento;
   }

   /**
    * @param string
    */
   public void setEvento(Evento e) {
       evento = e;
   }

    public String getAnyo() {
        return anyo;
    }

    public void setAnyo(String anyo) {
        this.anyo = anyo;
    }

    public String getDia() {
        return dia;
    }

    public void setDia(String dia) {
        this.dia = dia;
    }

    public String getMes() {
        return mes;
    }

    public void setMes(String mes) {
        this.mes = mes;
    }
   
   
   
   
   public void reset(ActionMapping arg0, HttpServletRequest arg1)
    {
       ArrayList arrayDias = new ArrayList();
       ArrayList arrayMeses = new ArrayList();
       ArrayList arrayAnios = new ArrayList();
       String s ="";
       
       for(int i = 1;i<=31;i++){
          s = new Integer(i).toString();
          arrayDias.add(new LabelValueBean(s, s));
       }
       for(int i = 1; i<=12; i++)
       {
          s = new Integer(i).toString();
          arrayMeses.add(new LabelValueBean(s, s));
       }
       
       Calendar cal = Calendar.getInstance();
       int anyoActual = cal.get(Calendar.YEAR);
       
       for(int i = anyoActual; i >= 1900; i--)
       {
          s = new Integer(i).toString();
          arrayAnios.add(new LabelValueBean(s, s));
       }
       
       arg1.setAttribute("dias", arrayDias);
       arg1.setAttribute("mes", arrayMeses);
       arg1.setAttribute("anyo", arrayAnios);
    }
public Calendar getFechaEvento()
    {
        Calendar fechaEvento = creaFecha(anyo, mes, dia);
        return fechaEvento;
    }
  private Calendar creaFecha(String anyo, String mes, String dia) {
        Calendar calendario = Calendar.getInstance();
        int year = Integer.valueOf(anyo);
        int month = Integer.valueOf(mes);
        int date = Integer.valueOf(dia);
        
        calendario.set(year, month, date);      
        return calendario;
    }
   /**
    *
    */
   public EventoForm() {
       super();
       evento = new Evento();
       // TODO Auto-generated constructor stub
   }

   public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
       ActionErrors errors = new ActionErrors();
       if (evento==null) {
           errors.add("name", new ActionMessage("error.name.required"));
           // TODO: add 'error.name.required' key to your resources
       }
       return errors;
   }
}
